package com.lbs.jiepiaisi.activity;

import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.TestSignActivity;
import com.lbs.jiepiaisi.base.BaseActivity;
import com.lbs.jiepiaisi.view.LinePathView;

import java.io.IOException;

public class SignTextActivity extends BaseActivity {
    Button mClear;
    Button mSave;
    Button cAndel;
    LinePathView pathView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_text);
        setResult(RESULT_OK);
        findView();
        setListener();
        getNet();
    }

    private void findView(){
        mClear = (Button)findViewById(R.id.clear1);
        mSave = (Button)findViewById(R.id.save1);
        cAndel = (Button)findViewById(R.id.cancel);
        pathView = (LinePathView)findViewById(R.id.view);

    }

    private void setListener(){
        mSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pathView.getTouched()) {
                    try {
                        pathView.save(WorkHomeOrderAddActivity.path1, false, 10);

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    setResult(RESULT_OK);
                    finish();
                } else {
                    Toast.makeText(SignTextActivity.this, "您没有签名~", Toast.LENGTH_SHORT).show();
                }
            }
        });

        mClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("EEEEEEEEEE","|KLDSFJKLDJFL");
                pathView.clear();
            }
        });
        cAndel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(RESULT_CANCELED);
                finish();
            }
        });
    }

    private void getNet() {
        Log.e("MMMMMMMMMM","|KLDSFJKLDJFL");
        pathView.clear();
    }




    //这里是 在进入签名页面的时候将屏幕设置为横屏
    @Override
    protected void onResume() {
        /**
         * 设置为横屏
         */
        if(getRequestedOrientation()!= ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
        super.onResume();
    }
}
